﻿Imports System.Data.OleDb

Public Class UploadCar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_Submit_Click(sender As Object, e As EventArgs) Handles btn_Submit.Click
        Dim newFileLoc As String = ""
        If fup_Picture.HasFile Then
            newFileLoc = Request.MapPath("pictures")
            newFileLoc = newFileLoc & "/" & fup_Picture.FileName
            fup_Picture.SaveAs(newFileLoc)
        Else
            Return
        End If

        Dim conn As New OleDbConnection(ConfigurationManager.ConnectionStrings("CarsConn").ConnectionString)
        Dim sql As String = "INSERT INTO ClassicCars (ModelName,ModelYear,CC,Make,Condition,Color,Registration,Price,ContactNumber,Picture,InfoUrl,SellerPostCode) VALUES (@f1,@f2,@f3,f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12)"
        Dim cmd As New OleDbCommand(sql, conn)
        conn.Open()
        cmd.Parameters.AddWithValue("@f1", tb_Modelname.Text)
        cmd.Parameters.AddWithValue("@f2", CInt(tb_ModelYear.Text))
        cmd.Parameters.AddWithValue("@f3", CInt(tb_Cc.Text))
        cmd.Parameters.AddWithValue("@f4", tb_Make.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Condtion.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Color.Text)
        cmd.Parameters.AddWithValue("@f7", tb_Registration.Text)
        cmd.Parameters.AddWithValue("@f8", CInt(tb_Price.Text))
        cmd.Parameters.AddWithValue("@f9", tb_ContactNumber.Text)
        cmd.Parameters.AddWithValue("@f10", "pictures/" & fup_Picture.FileName)
        cmd.Parameters.AddWithValue("@f11", tb_InfoUrl.Text)
        cmd.Parameters.AddWithValue("@f12", tb_SellerPostCode.Text)

        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("Default.aspx")
    End Sub
End Class